
<?php
// 新闻列表
  ob_clean();



  //固定每页显示的记录数
  $per_page = 5;

  $cur_page = empty($_GET['p'])?1:$_GET['p'];//获取地址栏的页码参数 （当前访问的页码）

  //求limit的偏移量
  $offset = ($cur_page-1)*$per_page;

  // 调用翻页函数
  $pages = getPages($link,'news',$cur_page,$per_page);

  $list = getSelect('news`,`cate','`news`.cate_id = `cate`.id and endble=0','`news`.`id` desc',"$offset,$per_page",'news.*,cate.name');


  //批量删除
  if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_GET['del'])){

    $id = explode(',',$_GET['id']);// 1,2,3,4,5
    $row= del($GLOBALS['c'],$id);

     // 调用翻页函数
    $pages = getPages($link,'news',$cur_page,$per_page);

    $list = getSelect('news`,`cate','`news`.cate_id = `cate`.id and endble=0','`news`.`id` desc',"$offset,$per_page",'news.*,cate.name');


      $json[0]['list']=$list;
      $json[0]['pages']=$pages;
      $json['row']=$row;
      echo json_encode($json);die;


  }



  // 批量审核  通过or不通过
  if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_GET['check'])){

    $id = $_GET['id'];
    $status = $_GET['status'];

    if($status!=0){

      if(!empty($_GET['b'])){
        $sql = "update `news` set `status`='$status' where `id` in ($id)";

      }else{
        $sql = "update `news` set `status`='$status' where `id`=$id";

      }
        mysqli_query($link,$sql);
        echo  mysqli_affected_rows($link);die;
    }

  }



  // 判断是否是ajax请求
  if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
    $json['list']=$list;
    $json['pages']=$pages;
    echo json_encode($json);die;
  }//print_r($data);die;

//加载后台公共视图
 include (View_PATH.$admin.'/communal.html');


?>

